package org.createModel.singleton.demo8;

/**
 * 饿汉式
 * 静态代码块
 */
public class Singleton {

    private Singleton() {
        // 解决反射创建多个对象
        if (instance != null) {
            throw new RuntimeException("不能创建多个对象");
        }
    }

    private static Singleton instance;

    static {
        instance = new Singleton();
    }

    public static Singleton getInstance() {
        return instance;
    }
}
